package com.mes.data.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mes.common.core.utils.poi.ExcelUtil;
import com.mes.common.core.web.controller.BaseController;
import com.mes.common.core.web.domain.AjaxResult;
import com.mes.common.core.web.page.TableDataInfo;
import com.mes.common.log.annotation.Log;
import com.mes.common.log.enums.BusinessType;
import com.mes.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mes.data.domain.DataReport;
import com.mes.data.service.IDataReportService;

/**
 * 数据分析报告主表Controller
 * 
 * @author itflash
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/data/report")
public class DataReportController extends BaseController
{
    @Autowired
    private IDataReportService dataReportService;

    /**
     * 查询数据分析报告主表列表
     */
    @RequiresPermissions("data:report:list")
    @GetMapping("/list")
    public TableDataInfo list(DataReport dataReport)
    {
        startPage();
        List<DataReport> list = dataReportService.selectDataReportList(dataReport);
        return getDataTable(list);
    }

    /**
     * 导出数据分析报告主表列表
     */
    @RequiresPermissions("data:report:export")
    @Log(title = "数据分析报告主表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataReport dataReport)
    {
        List<DataReport> list = dataReportService.selectDataReportList(dataReport);
        ExcelUtil<DataReport> util = new ExcelUtil<DataReport>(DataReport.class);
        util.exportExcel(response, list, "数据分析报告主表数据");
    }

    /**
     * 获取数据分析报告主表详细信息
     */
    @RequiresPermissions("data:report:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dataReportService.selectDataReportById(id));
    }

    /**
     * 新增数据分析报告主表
     */
    @RequiresPermissions("data:report:add")
    @Log(title = "数据分析报告主表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataReport dataReport)
    {
        return toAjax(dataReportService.insertDataReport(dataReport));
    }

    /**
     * 修改数据分析报告主表
     */
    @RequiresPermissions("data:report:edit")
    @Log(title = "数据分析报告主表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataReport dataReport)
    {
        return toAjax(dataReportService.updateDataReport(dataReport));
    }

    /**
     * 删除数据分析报告主表
     */
    @RequiresPermissions("data:report:remove")
    @Log(title = "数据分析报告主表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dataReportService.deleteDataReportByIds(ids));
    }
}
